#include "internal.h"

static void detach_entity_cfs_rq(struct sched_entity *se)
{
    struct cfs_rq *cfs_rq = cfs_rq_of(se);

#ifdef CONFIG_SMP
    /*
     * In case the task sched_avg hasn't been attached:
     * - A forked task which hasn't been woken up by wake_up_new_task().
     * - A task which has been woken up by try_to_wake_up() but is
     *   waiting for actually being woken up by sched_ttwu_pending().
     */
    if (!se->avg.last_update_time)
        return;
#endif

    /* Catch up with the cfs_rq and remove our load when we leave */
    update_load_avg(cfs_rq, se, 0);
    detach_entity_load_avg(cfs_rq, se);
    update_tg_load_avg(cfs_rq);
    propagate_entity_cfs_rq(se);
}

static void detach_task_cfs_rq(struct task_struct *p)
{
    struct sched_entity *se = &p->se;

    detach_entity_cfs_rq(se);
}

static void switched_from_fair(struct rq *rq, struct task_struct *p)
{
    detach_task_cfs_rq(p);
}
